﻿using System;
using System.Data;
using System.Data.SQLite;
using CompactMapper.Orm.Extensions;
using CompactMapper.Orm.UnitOfWork.Mappings;

namespace CompactMapper.Orm.UnitOfWork.Commands.Criteria
{
    internal sealed class IntegerEqualsCriterion<T> : Criterion<T>
    {
        public IntegerEqualsCriterion(Queries.Criterion<T> criterion, TablesTree tablesTreeRoot)
            : base(criterion, tablesTreeRoot)
        {
        }

        public override SQLiteParameter SQLiteParameter()
        {
            var parameter = new SQLiteParameter
                                {
                                    DbType = DbType.Int32,
                                    ParameterName = PropertyName.ToSqlValue(),
                                    Value = (int) TargetValue
                                };
            return parameter;
        }

        protected override string ToSql()
        {
            return String.Format("{0}={1}", PropertyName.ToSqlColumn(), PropertyName.ToSqlValue());
        }
    }
}